package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import biz.DriverBiz;
import biz.impl.DriverBizImpl;
import entity.Driver;

@WebServlet("/DriverLoginServlet.html")
public class DriverLoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userName=request.getParameter("driverUsername");
		String password=request.getParameter("driverPassword");
		DriverBiz driverBiz= new DriverBizImpl();
		Driver driver = driverBiz.loginDriver(userName, password);
		if(driver!=null){
			request.getSession().setAttribute("driver", driver);
			response.sendRedirect(request.getContextPath()+"/driver/driverManager.html");
		}else{
			request.setAttribute("error", "用户名或密码错误");
			request.getRequestDispatcher("driverLogin.jsp").forward(request, response);
		}
	}

}
